package com.je180503.dao.impl;

import com.je180503.dao.NewsTypeMapper;
import com.je180503.dao.util.MyBatisUtil;
import com.je180503.pojo.NewsType;
import org.apache.ibatis.session.SqlSession;


import java.util.List;

public class NewsTypeMapperImpl implements NewsTypeMapper {

    NewsTypeMapper newsTypeMapper=null;
    SqlSession sqlSession=null;



    @Override
    public int save(NewsType newType) {
        if (newType.getParentId().equals(0)){

            newType.setParentId(null);
        }
        sqlSession=MyBatisUtil.getSqlSession();
        newsTypeMapper=sqlSession.getMapper(NewsTypeMapper.class);
        int result=newsTypeMapper.save(newType);
        sqlSession.commit();
        //MyBatisUtil.closeSqlSession();
        return result;
    }



    @Override
    public List<NewsType> getTopNewsTypeList() {
        newsTypeMapper=MyBatisUtil.getSqlSession().getMapper(NewsTypeMapper.class);
        List<NewsType> list=newsTypeMapper.getTopNewsTypeList();
        MyBatisUtil.closeSqlSession();

        return list;
    }


}
